#!/usr/bin/env python3
"""
简单的服务器启动脚本
"""
import subprocess
import sys
import os

def main():
    """启动服务器"""
    try:
        # 切换到magazine目录
        os.chdir(os.path.dirname(os.path.abspath(__file__)))
        
        # 确保上传目录存在
        upload_dir = "static/uploads"
        if not os.path.exists(upload_dir):
            os.makedirs(upload_dir, exist_ok=True)
            print(f"✅ 创建上传目录: {upload_dir}")
        
        print("🚀 正在启动PWA增强版服务器...")
        print("📁 工作目录:", os.getcwd())
        
        # 启动服务器
        result = subprocess.run([sys.executable, "simple_server.py"], 
                              capture_output=True, text=True)
        
        if result.returncode != 0:
            print("❌ 服务器启动失败:")
            print("STDOUT:", result.stdout)
            print("STDERR:", result.stderr)
        else:
            print("✅ 服务器输出:", result.stdout)
            
    except Exception as e:
        print(f"❌ 启动错误: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    main()